let queue = [];
let waiting = false;
let timeFunc;
/*
vue这里做了兼容 Promise > ie MuationObserver > setImmediate > setTimeout
*/
if (typeof Promise !== 'undefined'){
    timeFunc = function(){
        return Promise.resolve().then(flushCallbacks);
    };
}else{
    timeFunc = function(){
        setTimeout(flushCallbacks);
    }
}
export function nextTick(cb){
    // 存到队列里, setTimeout一起触发。queueWatcher也使用了此方法
    queue.push(cb);
    if(!waiting){
        waiting = true;
        timeFunc();
    }
}

function flushCallbacks(){
    const cbs = queue.slice();
    queue = [];
    waiting = false;
    for (let i=0; i<cbs.length; i++){
        cbs[i]();
    }
}